<template>
  <div>
    <el-form :model="loginForm" status-icon :rules="rules" ref="ruleForm" @submit.native.prevent>
      <el-form-item prop="email" >
        <el-input type="text" v-model="loginForm.email" autocomplete="off" placeholder="邮箱" clearable ></el-input>
      </el-form-item>
      <el-form-item prop="password" >
        <el-input type="password" v-model="loginForm.password" autocomplete="off" placeholder="密码" show-password></el-input>
      </el-form-item>
      <el-form-item prop="agreed" style="margin-bottom: 5px">
        <el-checkbox v-model="loginForm.agreed"></el-checkbox>
        <span style="margin-left: 5px;color: gray">已阅读并同意小米帐号</span><a href="" style="color: black"> 用户协议 </a>和 <a href="" style="color: #333333">隐私政策</a>
  <!--      <br>-->
  <!--      <span v-if="!agreed">不同意隐私政策还想登陆？做梦！</span>-->
      </el-form-item>
      <el-form-item >
        <el-button
            :loading="loading"
            type="primary"
            @click="submitForm('ruleForm')"
            style="width: 100%;background-color: coral;border-color: coral"
        >
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
    <div style="width: 100%">
      <table style="width: 100%">
        <tr>
          <td><a href="https://account.xiaomi.com/fe/service/forgetPassword?_qrsize=180&_bannerBiz=&sid=mi_eshop&callback=http%3A%2F%2Forder.mi.com%2Flogin%2Fcallback%3Ffollowup%3Dhttps%253A%252F%252Fwww.mi.com%252F%26sign%3DNzY3MDk1YzczNmUwMGM4ODAxOWE0NjRiNTU5ZGQyMzFhYjFmOGU0Nw%2C%2C&qs=&_locale=zh_CN">忘记密码？</a></td>
          <td align="right" ><a href="#">手机号登录</a></td>
        </tr>
        <tr>
          <td colspan="2" align="center" style="color: #99a9bf">其他方式登录</td>
        </tr>
        <tr>
          <td colspan="2" align="center" >
            <a href="" ><img src="@/assets/loginPage/Alipay.png" alt="图片丢失"></a>
            <a href="" style="margin-left: 20px"><img src="@/assets/loginPage/QQ.png" alt="图片丢失"></a>
            <a href="" style="margin-left: 20px"><img src="@/assets/loginPage/wechat.png" alt="图片丢失"></a>
            <a href="" style="margin-left: 20px"><img src="@/assets/loginPage/weibo.png" alt="图片丢失"></a>
          </td>
        </tr>
      </table>
    </div>
  </div>
</template>

<script>
import { validateEmail } from "@/utils/formValidator";

export default {
  name: "loginForm",
  data() {
    return {
      loginForm: {
        email: '',
        password: '',
        agreed: '',
        uuid: "",
      },
      rules: {
        email: [
          { required: true, validator: validateEmail, trigger: 'blur'}
        ],
        password: [
          { required: true, message: '*请输入密码'}
        ],
      },
      loading: false,
    };
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
          this.loading = true
          // alert('submit!');
          if (this.loginForm.agreed) {
            this.$store.dispatch("Login", this.loginForm).then(() => {
              // 后退一步，返回登陆前的页面
              history.go(-1)
            }).catch(() => {
              this.loading = false;
            });
          } else {
            alert('*需要先同意隐私条款才可登陆！')
            this.loading = false;
            return false;
          }
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
    resetForm(formName) {
      this.$refs[formName].resetFields();
    }
  },
}
</script>

<style scoped>
.el-form {
  padding-top: 20px;
}
a {
  text-decoration: none;
  color: #ff5c00;
}
/deep/ .el-input__inner{
  height: 60px;
}
</style>

